package com.xbongbong.pro.message.pushset;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.message.domain.entity.PushSetEntity;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.pro.message.base.AbstractPushSet;
import com.xbongbong.pro.message.constant.PushSetConstant;
import com.xbongbong.pro.message.enums.PushObjectTypeEnum;
import com.xbongbong.pro.message.enums.PushTypeEnum;
import com.xbongbong.pro.message.model.PushSetModel;
import com.xbongbong.saas.constant.BasicConstant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 预付款消息推送
 * @author zcp
 * @version v1.0
 * @since v1.0
 */
public class PaySheetPrepaySet extends AbstractPushSet {

    @Override
    public PushSetEntity toPushSetEntity(String pushObject, String pushTime, String attrEntity) {
        return null;
    }

    @Override
    public PushSetEntity getPushSet(String corpid, Integer subType, PushSetModel pushSetModel) {
        Integer type = PushTypeEnum.PAY_SHEET_PREPAY_ADD.getCode();

        Map<String,Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("corpid", corpid);
        param.put("type", type);
        param.put("subType", subType);
        List<PushSetEntity> pushSetList = pushSetModel.findEntitys(param);

        PushSetEntity pushSetEntity;
        if(pushSetList.isEmpty()){
            pushSetEntity = new PushSetEntity();
            pushSetEntity.setType(type);
            pushSetEntity.setSubType(subType);
            pushSetEntity.setEnable(BasicConstant.ZERO);
            JSONObject pushObject = new JSONObject();
            if (Objects.equals(PushTypeEnum.PAY_SHEET_PREPAY_ADD.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.PAY_SHEET_PREPAY_ADD.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.PAY_SHEET_PREPAY_ADD));
                //type
                JSONArray typeArray = new JSONArray();
                JSONObject object = new JSONObject();
                object.put("name", PushObjectTypeEnum.MAINUSER.getName());
                object.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
                object.put("enable", 1);
                typeArray.add(object);
                JSONObject object1 = new JSONObject();
                object1.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
                object1.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
                object1.put("enable", 0);
                typeArray.add(object1);
                pushObject.put("type", typeArray);
                //manager
                JSONObject managerObject = new JSONObject();
                managerObject.put("enable", 0);
                managerObject.put("value", new ArrayList<>());
                pushObject.put("manager", managerObject);
                //dep
                JSONObject depObject = new JSONObject();
                depObject.put("enable", 0);
                depObject.put("value", new ArrayList<>());
                pushObject.put("dep", depObject);
                //role
                JSONObject roleObject = new JSONObject();
                roleObject.put("enable", 0);
                roleObject.put("value", new ArrayList<>());
                pushObject.put("role", roleObject);
                //user
                JSONObject userObject = new JSONObject();
                userObject.put("enable", 0);
                userObject.put("value", new ArrayList<>());
                pushObject.put("user", userObject);
            }
            pushSetEntity.setPushObject(pushObject.toJSONString());
        } else {
            pushSetEntity = pushSetList.get(0);
            if (Objects.equals(PushTypeEnum.PAY_SHEET_PREPAY_ADD.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.PAY_SHEET_PREPAY_ADD.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.PAY_SHEET_PREPAY_ADD));
            }
        }
        return pushSetEntity;
    }

    @Override
    public PushSetEntity getPushSet(String corpid, String attr, PushSetModel pushSetModel) {
        return null;
    }

    @Override
    public List<PushSetEntity> getPushSet(String corpid, List<String> attrList, PushSetModel pushSetModel, Long templateId) {
        return null;
    }

    @Override
    public JSONObject getTimeJson(JSONObject jsonObject) {
        return null;
    }
}
